using Holoville.HOTween;
using UnityEngine;

public class EndPvpMapBtn : MonoBehaviour
{
	[SerializeField]
	private UITexture texture;

	[SerializeField]
	private UISprite reputationBar;

	[SerializeField]
	private UISprite reputationBarBG;

	[SerializeField]
	private new UILabel name;

	[SerializeField]
	private UILabel infoText;

	[SerializeField]
	private UIWidget topWidget;

	[SerializeField]
	private UISprite reputationCapturedBar;

	[SerializeField]
	private UISprite reputationCapturedEliteBar;

	private LevelsInfo levelInfo;

	[SerializeField]
	public EndPvpMapBtnSettings[] settings;

	public void OnClick()
	{
		LoadLevel();
	}

	public void OnEnable()
	{
		topWidget.alpha = 0f;
	}

	public void SetMap(LevelsInfo info, ReputationMapInfo reputationInfo, float lowPercent, float highPercent, bool needSkipreputationBar = false)
	{
		texture.mainTexture = Resources.Load<Texture>("ReputationMap/Icons/" + info.nameScene);
		name.text = info.localizedName;
		levelInfo = info;
		EndPvpMapBtnSettings.EndPvpMapBtnState endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.NotCaptured;
		if (!needSkipreputationBar)
		{
			if (reputationInfo.wasLosted)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.Losted;
				reputationBar.gameObject.SetActive(true);
				reputationCapturedBar.gameObject.SetActive(false);
				reputationCapturedEliteBar.gameObject.SetActive(false);
				if (reputationBar != null)
				{
					reputationBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else if (reputationInfo.state == DistrictState.Captured && reputationInfo.reputationPercent < lowPercent && !reputationInfo.elite)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.AlmostLost;
				reputationBar.gameObject.SetActive(false);
				reputationCapturedBar.gameObject.SetActive(true);
				reputationCapturedEliteBar.gameObject.SetActive(false);
				if (reputationCapturedBar != null)
				{
					reputationCapturedBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else if (reputationInfo.state == DistrictState.Unlocked && reputationInfo.reputationPercent > highPercent)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.AlmostCaptured;
				reputationBar.gameObject.SetActive(true);
				reputationCapturedBar.gameObject.SetActive(false);
				reputationCapturedEliteBar.gameObject.SetActive(false);
				if (reputationBar != null)
				{
					reputationBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else if (reputationInfo.state == DistrictState.Captured && !reputationInfo.elite)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.Captured;
				reputationBar.gameObject.SetActive(false);
				reputationCapturedBar.gameObject.SetActive(true);
				reputationCapturedEliteBar.gameObject.SetActive(false);
				if (reputationCapturedBar != null)
				{
					reputationCapturedBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else if (reputationInfo.elite && reputationInfo.reputationPercent < lowPercent && reputationInfo.state == DistrictState.Captured)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.Elite;
				reputationBar.gameObject.SetActive(false);
				reputationCapturedBar.gameObject.SetActive(false);
				reputationCapturedEliteBar.gameObject.SetActive(true);
				if (reputationCapturedEliteBar != null)
				{
					reputationCapturedEliteBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else if (reputationInfo.state == DistrictState.Captured && reputationInfo.elite)
			{
				endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.Captured;
				reputationBar.gameObject.SetActive(false);
				reputationCapturedBar.gameObject.SetActive(false);
				reputationCapturedEliteBar.gameObject.SetActive(true);
				if (reputationCapturedEliteBar != null)
				{
					reputationCapturedEliteBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
			else
			{
				reputationBar.gameObject.SetActive(true);
				reputationCapturedBar.gameObject.SetActive(false);
				reputationCapturedEliteBar.gameObject.SetActive(false);
				if (reputationBar != null)
				{
					reputationBar.fillAmount = reputationInfo.reputationPercent;
				}
			}
		}
		HOTween.To(topWidget, 0.5f, new TweenParms().Prop("alpha", 1f));
	}

	public UISprite ChooseProgressBar(LevelsInfo info, ReputationMapInfo reputationInfo, float lowPercent, float highPercent)
	{
		texture.mainTexture = Resources.Load<Texture>("ReputationMap/Icons/" + info.nameScene);
		name.text = info.localizedName;
		levelInfo = info;
		EndPvpMapBtnSettings.EndPvpMapBtnState endPvpMapBtnState = EndPvpMapBtnSettings.EndPvpMapBtnState.NotCaptured;
		if (reputationInfo.state == DistrictState.Unlocked)
		{
			reputationBar.gameObject.SetActive(true);
			reputationCapturedBar.gameObject.SetActive(false);
			reputationCapturedEliteBar.gameObject.SetActive(false);
			HOTween.To(topWidget, 0.5f, new TweenParms().Prop("alpha", 1f));
			return reputationBar;
		}
		if (reputationInfo.state == DistrictState.Captured && !reputationInfo.elite)
		{
			reputationBar.gameObject.SetActive(false);
			reputationCapturedBar.gameObject.SetActive(true);
			reputationCapturedEliteBar.gameObject.SetActive(false);
			HOTween.To(topWidget, 0.5f, new TweenParms().Prop("alpha", 1f));
			return reputationCapturedBar;
		}
		if (reputationInfo.state == DistrictState.Captured && reputationInfo.elite)
		{
			reputationBar.gameObject.SetActive(false);
			reputationCapturedBar.gameObject.SetActive(false);
			reputationCapturedEliteBar.gameObject.SetActive(true);
			HOTween.To(topWidget, 0.5f, new TweenParms().Prop("alpha", 1f));
			return reputationCapturedEliteBar;
		}
		return reputationBar;
	}

	public void LoadLevel()
	{
		MessageWindow.instance.ToggleBlockPanel(true);
		controllerConnectPhoton.thisScript.connectRandomRoom(levelInfo.nameScene, levelInfo.modeGame);
		controllerConnectGame.thisScript.SetRoomTimeOut();
	}
}
